I2C Bus Services:
5.1. Q - What services are available for I2C Bus access?
A - I2C Bus is accessed via message queues and semaphores. At first this might seem a bit
difficult but the system works quite well. The services provided allow user programs to
access the I2C bus in a consistent way that insures all I2C user functions work together.
The steps needed to access the I2C bus are as follows:
1. Create a task.
2. The user task requests exclusive access to the I2C bus.
Start a "OS_WaitMsg(MSG_I2C_ACCESS, &msgP, OSNO_TIMEOUT, task_label);"
3. Now that we have the I2C bus to ourselves, load the i2c_control structure indicating
structure indicating the I2C bus action needed.
4. Signal the I2C master handler via "OSSignalMsg(MSG_I2C_QUERY, (OStypeMsgP) 1);"
5. Wait for the I2C master handler to signal I/O completion via:
"OS_WaitMsg(MSG_I2C_RESPONSE, &msgP, OSNO_TIMEOUT, task_label);"
6. Process the data transferred from the I2C device.
7. Release the I2C bus. This is very important!
If the bus is not released all other I2C bus applications will be locked out!
To release the bus do:
OSProtect();
OSSignalMsg(MSG_I2C_ACCESS, (OStypeMsgP) 1);
OSUnprotect();
5.2. Q - Is there sample programs I can look at?
A - The perfect I2C starter program is the thermal sensor access code.
This is in the therm.c source file. It is a very small app that accesses the I2C bus
for reading only.
Other programs are:
rtc.c - Relatively complex example. Reads and writes to I2C device.
This program accesses the Real Time Clock(RTC).
seeprom.c - Medium complexity. Both read and writes to I2C devices.
This program accesses the serial EEPROM chips.
seepromex.c - This is an optional program which, when compiled in, will
give status of the serial EEPROM chips.
i2c.c - This is the I2C master controller. All I2C functions access the
functions defined here.
Warning: The functions in this file are VERY timing sensitive.
Be careful when making changes.